package com.atguigu.lease.common.exception;


import com.atguigu.lease.common.result.Result;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author yjf
 * @version 1.0
 * @description: TODO
 * @date 2024/9/10 16:49
 */
@RestControllerAdvice //@ControllerAdvice + ResponseBody
public class GlobalExceptionHandler {
    @ExceptionHandler(LeaseException.class)
    //处理异常的方法
    //@ExceptionHandler注解中可以添加参数，参数是某个异常类的class，代表这个方法专门处理该类异常
    public Result resolveLeaseException(LeaseException leaseException){
        leaseException.printStackTrace();
        return Result.fail(leaseException.getCode(),leaseException.getMessage());
    }
    //未知异常
    @ExceptionHandler(Exception.class)
    public Result resolveException(Exception e){
        e.printStackTrace();  //打印堆栈跟踪信息
        return Result.fail();
    }
}
